import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        # self.pack(expand=True, fill=tk.BOTH)
        # self.pack(side="left")
        self.create_widgets()

    def create_widgets(self):
        self.label1 = tk.Label(self, text="天津大学", width=10, height=2, background='blue', foreground='yellow',
                               font=("黑体", 40))
        self.label1.pack()
        self.label2 = tk.Label(self, text="天津市南开区卫津路92号", width=24, height=2, background='black', foreground='white',
                               font=("楷体", 20))
        self.label2.pack()
        global badge  # 注意：局部变量会被tkinter优化掉，要么使用全局变量要么使用类的成员变量
        self.badge = tk.PhotoImage(file="badge.gif")
        self.label3 = tk.Label(self, image=self.badge, width=531, height=162)
        self.label3.pack()
        self.label4 = tk.Label(self, text="天津大学\r\n精密仪器与光电子工程学院", width=24, height=3, borderwidth=1,
                               relief="solid", justify='right', font=("黑体",20))
        self.label4.pack()
        from PIL import Image,ImageTk
        self.cellSize = 50
        # self.lable5 = tk.Label(self.master, bd=0)
        self.lable5 = tk.Label(self, bd=0)
        img = Image.new(
            'RGB', (self.cellSize, self.cellSize))
        img = ImageTk.PhotoImage(img)
        self.lable5.configure(image=img)
        self.lable5['width'] = self.cellSize
        self.lable5['height'] = self.cellSize
        self.lable5['text'] = '10'
        self.lable5['font'] = ("黑体",20)
        self.lable5['background']='yellow'
        self.lable5['compound'] = 'center'
        self.lable5.place(x=0, y=0)

    def say_hi(self):
        print("hi there, everyone!")

root = tk.Tk()
root.geometry('800x600+300+200')
app = Application(master=root)
app.mainloop()